// pages/ScenicArea/ScenicAreaCommitPage/index.js
var common = require("../../../../public.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showBuyerPanel: false,
        storeInfo: {},
        ticketOrder: '',
        orderNo: '',
        isLoading: false,
        orderobj: "",
        ticketTime: '',
        timeData: {},
        flag_fail: false,
        message: '',
    },
    onChange(event) {
        this.setData({
            message: event.detail
        })
    },
    onLoad: function (options) {
        const that = this
        console.log(options)
        wx.getStorage({
            key: 'user',
            success: function (res) {
                that.setData({
                    userInfo: res.data.user,
                    token: res.data.token,
                    openid: res.data.openid,
                    orderNo: options.orderNo,
                    orderobj: options.obj
                }, () => {
                    that.initData();
                })
            }
        })
    },
    initData() {
        const that = this
        let tempJson = {
            userId: that.data.userInfo.id,
            token: that.data.token,
            orderNo: that.data.orderNo,
        }
        this.setData({
            isLoading: true
        })
        common.post('/venueOrder/getMyOrderInfo', tempJson, function (res) {
            if (res.status === 200) {
                that.setData({
                    storeInfo: res.data.store,
                    ticketOrder: res.data.orderInfo,
                })
            } else {
                common.showRequestErrMsg(res)
            }
        }, function () {
            that.setData({
                isLoading: false
            })
        })
    },
    // 取消支付
    click_qv() {
        var that = this
        const pages = getCurrentPages();
        const prevPage = pages[pages.length - 2]; //上一个页面
        // 从朋友圈进入的时候，页面栈为空，这里需要判断是否有上个页面
        if (prevPage) {
            wx.navigateBack({
                delta: 1
            })

        }
    },

    toEticket() {
        if (this.data.ticketOrder.status == 2 || this.data.ticketOrder.status == 5) {
            wx.navigateTo({
                url: '/pages/ScenicArea/ScenicAreaETicket/index?orderNo=' + this.data.ticketOrder.orderNo,
            })
        } else {
            common.showToast('当前订单不可查看电子票')
        }
    },
    toStore() {
        const type = this.data.storeInfo.storeType == 6 ? 1 : 2
        wx.navigateTo({
            url: '/pages/ScenicArea/ScenicAreaMainPage/index?moduleType=' + type + '&id=' + this.data.storeInfo.id,
        })
    },
    makePhone() {
        wx.makePhoneCall({
            phoneNumber: this.data.storeInfo.mobile,
        })
    },
    goback() {
        wx.navigateBack({
            delta: 1,
        })
    },
    refund() {
        const that = this
        common.showAlertView('提示', '您确定要申请退款吗？', function (sure) {
            if (sure) {
                const param = {
                    orderNo: that.data.ticketOrder.orderNo,
                    refundAmount: that.data.ticketOrder.payment,
                    refundReason: that.data.message,
                    userId: that.data.userInfo.id,
                    token: that.data.token,
                }
                common.post('/venueOrder/refundTVenueOrder', param, function (res) {
                    if (res.status === 200) {
                        const pages = getCurrentPages()
                        const prePage = pages[pages.length - 2]
                        wx.navigateBack({
                            delta: 1,
                            success: function () {
                                common.showToast('退款申请发送成功')
                                if (prePage && prePage.reloadData) {
                                    prePage.reloadData()
                                }
                            }
                        })
                    } else {
                        common.showRequestErrMsg(res)
                    }
                })
            }
        })
    }
})